package com.kexun.servlet.admin;

import com.kexun.pojo.User;
import com.kexun.service.AdmService;
import com.kexun.service.impl.AdmServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletEditUsrInfo")
public class ServletEditUsrInfo extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String userNum = request.getParameter("userNum");
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");
        String phone = request.getParameter("phone");
        String roleName = request.getParameter("roleId");
        int roleId = 0;

        switch (roleName){
            case "学生": roleId = 0;break;
            case "老师": roleId = 1;break;
            case "管理员":roleId = 2;break;
            default:break;
        }

        User user = new User(userNum, userName, password, phone, roleId);
        AdmService as = new AdmServiceImpl();
        int i = as.editUsr(user);
        if(i>0){
            response.getWriter().print("修改成功");
            response.setHeader("refresh","1;url=admin/updUser.html");
        }



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
